validate

Purpose

Validates a domain class against the applied constraints (see Validation)

Description

The validate method will validate a domain class based on its defined constraints. The errors will be stored within the errors object.

The validate method accepts an optional List argument which may contain the names of the properties that should be validated. When a List is passed to the validate method, only the properties defined in the List will be validated.

Examples

def b = new Book(title:"The Shining")
if( !b.validate() ) {
   b.errors.each {
        println it
   }
}

def a = new Album(artist: "Genesis", title: "Nursery Cryme", releaseDate: 1971)

// only validate title and releaseDate if( !a.validate(["title", "releaseDate"]) ) { a.errors.each { println it } }